#include <cassert>

#include "MPoint.h"

MPoint::MPoint( float x, float y ) : _x( x ), _y( y ) 
{

}

MPoint::MPoint( const MPoint& point ) :	_x( point.x() ), _y( point.y() )
{

}

MPoint& MPoint::operator = ( const MPoint& point )
{ 
	_x = point.x();
	_y = point.y();
	return *this;
}

MPoint::~MPoint()
{
}

void MPoint::setX( float x )
{
	_x = x;
}

float MPoint::x() const
{
	return _x;
}

void MPoint::setY( float y )
{
	_y = y;
}

float MPoint::y() const
{
	return _y;
}

MPoint MPoint::operator + ( const MPoint& point )
{
	return MPoint( x() + point.x(), y() + point.y() );
}

MPoint& MPoint::operator += ( const MPoint& point )
{
	setX( x() + point.x() );
	setY( y() + point.y() );
	return *this;
}

MPoint MPoint::operator - ( const MPoint& point )
{
	return MPoint( x() - point.x(), y() - point.y() );
}

MPoint MPoint::operator * ( const MPoint& point )
{
	return MPoint( x() * point.x(), y() * point.y() );
}

MPoint MPoint::operator / ( const MPoint& point )
{
	assert( point.x() );
	assert( point.y() );

	MPoint result;

	if ( point.x() )
	{
		result.setX( x() / point.x() );
	}

	if ( point.y() )
	{
		result.setY( y() / point.y() );
	}

	return result;
}

bool MPoint::operator > ( const MPoint& point )
{
	return ( _x > point.x() || _y > point.y() ) ? true : false;
}

std::ostream& operator << ( std::ostream& stream, const MPoint& point )
{
	stream << "MPoint x = " << point.x() << ", y = " << point.y() << std::endl;
	return stream;
}

MPoint MPoint::operator + ( float n )
{
	return MPoint( x() + n, y() + n );
}

MPoint MPoint::operator - ( float n )
{
	return MPoint( x() - n, y() - n );
}

MPoint MPoint::operator * ( float n )
{
	return MPoint( x() * n, y() * n );
}

MPoint MPoint::operator / ( float n )
{
	assert( n );

	MPoint result;

	if ( n )
	{
		result.setX( x() / n );
		result.setY( y() / n );
	}

	return result;
}

bool MPoint::operator > ( float n )
{
	return ( _x > n && _y > n ) ? true : false;
}

MPoint abs( MPoint& point )
{
	return MPoint( abs( point.x() ), abs( point.y() ) );
}